class Solution
{
public:
    bool backspaceCompare(string s, string t)
    {
        string sResult;
        string tResult;
        for (char c : s)
        {
            if (c == '#' && !sResult.empty())
            {
                sResult.pop_back();
            }
            if (c != '#')
            {
                sResult.push_back(c);
            }
        }
        for (char c : t)
        {
            if (c == '#' && !tResult.empty())
            {
                tResult.pop_back();
            }
            if (c != '#')
            {
                tResult.push_back(c);
            }
        }
        return sResult == tResult;
    }
};